/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package au.edu.swin.unilearn.subject;

import au.edu.swin.unilearn.assignment.AssignmentEntity;
import au.edu.swin.unilearn.tutorialGroup.TutorialGroupEntity;
import java.io.Serializable;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 *
 * @author DidierLeung
 */
@Entity
@NamedQueries({
@NamedQuery(name = "findAllSubjects", query = "SELECT se FROM SubjectEntity se")
})
@Table(name = "SUBJECTS")
public class SubjectEntity implements Serializable
{
    private static final long serialVersionUID = 1L;
    @Id
    @Column
    private String subject_code;
    @Column
    private String subject_name;
    @OneToMany(mappedBy = "subjectEntity", cascade=CascadeType.ALL)
    private List<AssignmentEntity> assignmentCollection;
    @OneToMany(mappedBy = "subjectEntity", cascade=CascadeType.ALL)
    private List<TutorialGroupEntity> tutorialGroupEntityCollection;
    public SubjectEntity()
    {
    }

    public SubjectEntity(String subject_code, String subject_name)
    {
        this();
        setSubject_code(subject_code);
        setSubject_name(subject_name);
    }

    public String getSubject_code()
    {
        return subject_code;
    }

    public void setSubject_code(String subject_code)
    {
        this.subject_code = subject_code;
    }

    public String getSubject_name()
    {
        return subject_name;
    }

    public void setSubject_name(String subject_name)
    {
        this.subject_name = subject_name;
    }

    public Subject getSubjectObject()
    {
        return new Subject(subject_code, subject_name);
    }

    public void setSubjectEntityData(Subject s)
    {
        setSubject_code(s.getSubject_code());
        setSubject_name(s.getSubject_name());
    }

    public List<AssignmentEntity> getAssignmentCollection()
    {
        return assignmentCollection;
    }

    public void setAssignmentCollection(List<AssignmentEntity> assignmentCollection)
    {
        this.assignmentCollection = assignmentCollection;
    }

    @Override
    public int hashCode()
    {
        return subject_code.hashCode();
    }

    @Override
    public boolean equals(Object object)
    {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof SubjectEntity))
        {
            return false;
        }
        SubjectEntity other = (SubjectEntity) object;
        if (this.subject_code.equals(other.getSubject_code()))
        {
            return false;
        }
        return true;
    }

    @Override
    public String toString()
    {
        return "au.edu.swin.mockup.SubjectEntity[id=" + this.subject_code + "]";
    }

    public List<TutorialGroupEntity> getTutorialGroupEntityCollection()
    {
        return tutorialGroupEntityCollection;
    }

    public void setTutorialGroupEntityCollection(List<TutorialGroupEntity> tutorialGroupEntityCollection)
    {
        this.tutorialGroupEntityCollection = tutorialGroupEntityCollection;
    }
}
